﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_DeleteStaff]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_DeleteStaff];
GO
CREATE PROCEDURE [dbo].[sproc_DeleteStaff] 
    @StaffName nvarchar(300)
AS
DECLARE @staffid int

IF EXISTS(SELECT 1 FROM uds_staff WHERE staff_name = @StaffName)
BEGIN

--BBS相关

--客户相关

--邮件相关

--任务相关

--删除流程人员相关
-----------------------------------------------------------
SELECT     @staffid = staff_id
    FROM 
        uds_staff 
    WHERE     staff_name = @StaffName

DELETE 
    FROM 
        uds_flow_document
    WHERE     doc_builder_id = @staffid


DELETE 
    FROM 
        uds_flow_path
    WHERE     staff_id = @staffid

DELETE 
    FROM 
        uds_flow_postil
    WHERE     postiler_id = @staffid

DELETE 
    FROM 
        uds_flow_status
    WHERE     staff_id = @staffid
-----------------------------------------------------------



--删除角色成员
-----------------------------------------------------------
DELETE 
    FROM 
        uds_staff_in_role
    WHERE     staff_id = @staffid
-----------------------------------------------------------



--删除项目成员
-----------------------------------------------------------
DELETE 
    FROM 
        uds_staff_in_team
    WHERE     staff_id = @staffid
-----------------------------------------------------------



--删除权限
-----------------------------------------------------------
DELETE 
    FROM 
        UDS_Assign_Rule
    WHERE     staff_id = @staffid
-----------------------------------------------------------



--删除职位
-----------------------------------------------------------
DELETE 
    FROM 
        uds_staff_in_position
    WHERE     staff_id = @staffid
-----------------------------------------------------------



--删除人员
-----------------------------------------------------------
DELETE 
    FROM 
        uds_staff
    WHERE     staff_id = @staffid
-----------------------------------------------------------
END
ELSE
    PRINT '查无此人！'